export const loadScript = ({ url, name }) => {
  return new Promise((resolve, reject) => {
    if (!name) {
      reject("no object name passed!");
      return;
    }
    if (document.querySelector(`script#${name}`)) {
      resolve(window[name]);
      return;
    }
    const script = document.createElement("script");
    script.src = url;
    script.id = name;
    script.onload = () => {
      resolve(window[name]);
    };
    script.onerror = () => {
      reject("load error");
    };
    document.body.appendChild(script);
  });
};
